﻿using LanqiQAwebapi.ConnectHubs;
using LanqiQAwebapi.Models;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
namespace LanqiQAwebapi.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    [EnableCors("AllowCors")]
    public class ChatController : ControllerBase
    {


        private readonly IHubContext<ConnectHub> _hubContext;
        public ChatController(IHubContext<ConnectHub> hubContext) 
        {

            _hubContext=hubContext;
        }

        [HttpPost("messages")]
        public async Task SendMessage(string userid, string message)
        {
            // 通过 HubContext 调用客户端的方法
            await _hubContext.Clients.User(userid).SendAsync("ReceiveMessage", userid, message);
        }

    }
}
